Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace obsolete react context #663

Conversation

pablopalacios
Copy link
Contributor

@pablopalacios pablopalacios commented Oct 25, 2020

Closes #584

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@pablopalacios
Copy link
Contributor Author

pablopalacios commented Oct 25, 2020

@redonkulus I gave it a try today. I just realized that there is another breaking change: since we are not using the old context anymore, we can't have in our API the feature of injecting other context values besides fluxible ones:

connectToStores

// before
function connectToStores(Component, stores, getStateFromStores, customContextTypes)

// after
function connectToStores(Component, stores, getStateFromStores)

provideContext

// before
function provideContext(Component, customContextTypes)

// after
function provideContext(Component)

Would it be a problem?

By the way, besides injecting react context values, provideContext was also using customContextTypes to extract values from the fluxible context and inject in the child context (perhaps a value added by a plugin). We could rewrite it in this way:

// before
function provideContext(Component, customContextTypes)

// after
function provideContext(Component, pluginsKeys)

provideContext(Component, ['plugin1', 'plugin2'])

What do you think? (was I clear enough?)

@pablopalacios pablopalacios marked this pull request as draft October 25, 2020 17:16
@redonkulus
Copy link
Contributor

I think that makes sense as long as users can still add to the context. Otherwise, we would have to recommend an alternative method. @lingyan can you remember often we add custom context values, I know plugins do, seems like this would be a common thing.

I would recommend testing this in the doc site to see if any other issues come up.

Unrelated, but it would be good to migrate to import / export in these files too. This would help with tree shaking as well.

@pablopalacios
Copy link
Contributor Author

@redonkulus Another breaking change while updating fluxible-router: NavLink use to have a possibility to use a custom logger through contextTypes as well. I removed that so I could consume fluxible-context easily inside the class. Would that be fine?

@pablopalacios
Copy link
Contributor Author

I think that makes sense as long as users can still add to the context. Otherwise, we would have to recommend an alternative method. @lingyan can you remember often we add custom context values, I know plugins do, seems like this would be a common thing.

I would recommend testing this in the doc site to see if any other issues come up.

Unrelated, but it would be good to migrate to import / export in these files too. This would help with tree shaking as well.

I didn't get what makes sense. I see 3 possibilities here:

  1. Remove customContextTypes support (users will have to come up with their own react context to provide fluxible plugin values);
  2. Convert customContextTypes object to pluginsKeys to an array. (Still breaking change, but we keep the feature);
  3. Keep as it is (no breaking changes, but it is unnecessary to get an object with prop-types);

For the commonjs issue, I've just create another PR (#664 )

@pablopalacios pablopalacios force-pushed the fluxible-addons-react-replace-old-context branch 2 times, most recently from 8d2ddf9 to b3a3c36 Compare October 26, 2020 10:17
@pablopalacios pablopalacios marked this pull request as ready for review November 2, 2020 15:19
@pablopalacios
Copy link
Contributor Author

@redonkulus I've added back the customContextTypes feature in provideContext. Now, one can pass an array of plugins keys to inject its content into the state provided by FluxibleProvider. It is still a breaking change but the migration should be simple (just extract the keys from customContextTypes into an array).

@redonkulus
Copy link
Contributor

@pablopalacios Sounds good. Can you start a MIGRATATION.md doc in this branch to keep track of the breaking changes and what the code changes will be?

@pablopalacios pablopalacios force-pushed the fluxible-addons-react-replace-old-context branch from 7170449 to 1070ad9 Compare November 3, 2020 13:24
@pablopalacios pablopalacios changed the title WIP: Replace obsolete react context Replace obsolete react context Nov 3, 2020
@pablopalacios
Copy link
Contributor Author

@redonkulus I've removed FluxibleConsumer and useFluxible from this PR since it is out of scope. So here you will find only the necessary steps to replace the obsolete react context. I created a initial document for the migration guide, but I did this in another PR (#665) so it doesn't block the code development.

By the way, would it be possible to rebase the 1.x-dev branch on top of master?

@redonkulus redonkulus force-pushed the fluxible-addons-react-1.x-dev branch from db1f963 to 145798d Compare November 3, 2020 13:56
@redonkulus
Copy link
Contributor

By the way, would it be possible to rebase the 1.x-dev branch on top of master?

@pablopalacios Ok I've rebased and pushed, please update your fork.

@pablopalacios pablopalacios force-pushed the fluxible-addons-react-replace-old-context branch from 1070ad9 to 0a51a12 Compare November 3, 2020 15:34
@pablopalacios pablopalacios force-pushed the fluxible-addons-react-replace-old-context branch from 0a51a12 to 2621d7d Compare November 11, 2020 17:34
@pablopalacios
Copy link
Contributor Author

@redonkulus, @lingyan any comments here?

@redonkulus
Copy link
Contributor

Sorry, I will get this merged and released today.

Copy link
Contributor

@redonkulus redonkulus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, thanks for all the work you are doing!

@redonkulus redonkulus merged commit 91b14bc into yahoo:fluxible-addons-react-1.x-dev Nov 11, 2020
@pablopalacios pablopalacios deleted the fluxible-addons-react-replace-old-context branch November 11, 2020 21:15
@pablopalacios pablopalacios restored the fluxible-addons-react-replace-old-context branch December 9, 2020 12:29
@pablopalacios pablopalacios deleted the fluxible-addons-react-replace-old-context branch May 13, 2021 09:18
pablopalacios added a commit to pablopalacios/fluxible that referenced this pull request Jul 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants